/**
 * 
 */
	function loaddata(){
		

		var allFlag = $("#allFlag").val();
		var pno = $("#pagenum").val();
		var from_date=$("#from_date").val();
		var to_date=$("#to_date").val();
		var type=$("#lossType_id").val();
		var ope_id=$("#ope_id_Ary").val();
		var classtype= $("#classtype").val();
		var url = pms_url + "ary/performance/getListMajorLoss";
		var params = {from_date:from_date,to_date:to_date,type:type,ope_id:ope_id,pno:pno,classtype:classtype,allFlag:allFlag};
		var obj = load(url,params);
		var majorLoss = obj.majorLoss;
		$("#performanceMaintainDaylist").find("tbody").html("");
		$.each(majorLoss, function(index, p) {
			var tr ="<tr role='row'>"+
			"<td align='center'>"+(index+1)+"</td>"+
			"<td align='center'>"+p.fab_date+"</td>"+
			"<td align='center'>"+p.category+"</td>"+
			"<td align='center'>"+p.label+"</td>"+
			"<td align='center'>"+p.emp_id+"</td>"+
			"<td align='center'>"+p.emp_name+"</td>"+
			"<td align='center'>"+((p.classtype==null)?"":p.classtype)+"</td>"+
			"<td align='center'>"+p.reason+"</td>"+
			"<td><button type='button' class='btn red btn-outline btn-xs del' value="+p.id+">删除</button></td>"+
			"</tr>";
				$("#performanceMaintainDaylist").find("tbody").append(tr);
			
	 });
	}


	
	
	



$(function () { 
	loaddata();
	
	$('#btnAdd').on('click', function () {
		$('#modalAdd').find("input").val("");
		$('#modalAdd').find("textarea").val("");
		$('#modalAdd').modal("show");
	});
	
	
	$("#btnReset").on('click', function () {
		$("#searchform input").val("");
		$("#searchform select").val("");
	});	
	
	
	$('#btnSearch').on('click', function () {
		$("#pagenum").val(1);
		loaddata();
	});
	
	$("#btnAddData").on('click', function () {
		var bootstrapValidator = $("#basicform").data('bootstrapValidator');
		   bootstrapValidator.validate();
		   if(bootstrapValidator.isValid()){
				var fabDate = $("#fabDate").val();
				var ope_id_ARY = $("#ope_id_ARY").val();
				var emp_id = $("#emp_id").val();
				var emp_name = $("#emp_name").val();
				var reason = $("#reason").val();
				var type = $("#lossType").val();
				
				var param = {fabDate:fabDate,type:type,ope_id_ARY:ope_id_ARY,emp_id:emp_id,
						emp_name:emp_name,reason:reason};
				var url = pms_url + "ary/performance/createByDay"; 
				$.ajax({  
					  type : "post",  
				        url : url,  
				        dataType: "json", 
				        data : param, 
				        async : false,  //同步
				        success : function(data){ 
					    		if(data.err_msg=="success"){
					    			alert("保存成功");
									$('#modalAdd').modal("hide");
									window.location.reload();
					    		}else {
					    			alert(data.err_msg);
					    		}
				        	}
				        });				   
			   }
			   else return;
		});
	
	
	
	
	
	$('#basicform').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok validator',
            invalid: 'glyphicon glyphicon-remove validator',
            validating: 'glyphicon glyphicon-refresh validator'
        },
        fields: {
        	factory: {
                message: 'The factory is not valid',
                validators: {
                    notEmpty: {
                        message: '工厂不能为空'
                    }
                }
        	},
        	type: {
                message: 'The type is not valid',
                validators: {
                    notEmpty: {
                        message: '异常类别不能为空'
                    }
                }
            },
            emp_id: {
                message: 'The emp_id is not valid',
                validators: {
                    notEmpty: {
                        message: '工号不能为空'
                    }
                }
            },
            group_leader: {
                message: 'The group_leader is not valid',
                validators: {
                    notEmpty: {
                        message: '组长姓名不能为空'
                    }
                }
            },
            reason: {
                message: 'The reason is not valid',
                validators: {
                    notEmpty: {
                        message: '内容不能为空'
                    }
                }
            },
            fabDate: {
                message: 'The fabDate is not valid',
                validators: {
                    notEmpty: {
                        message: '发生日期不能为空'
                    }
                }

            },
            ope_id: {
                message: 'The ope_id is not valid',
                validators: {
                    notEmpty: {
                        message: '异常站点不能为空'
                    }
                }
            },
            emp_name: {
                message: 'The emp_name is not valid',
                validators: {
                    notEmpty: {
                        message: 'DL姓名不能为空'
                    }
                }
            },
            class_type: {
                message: 'The class_type is not valid',
                validators: {
                    notEmpty: {
                        message: '班别不能为空'
                    },
                    regexp: {
                        regexp: /^[A-C]+$/ ,
                        message: '只能是字母'
                    }
                }
            }
            
        }
	});
	
	
	
	
	
	//删除员工的岗位信息
	$(document).on('click', ".del",function () {
		if(!confirm("是否确认删除！")){
			return;
		}
		
		var id = $(this).val();
//		alert(typeof(id));
		var param = {id:id};
		var delurl = pms_url + "ary/performance/deleteByDay";
		$.post(delurl, param, function(data) {
			if(data.err_msg=="success"){
				alert("删除成功！");
				loaddata();
//				$("#deptlist").find("tbody").html("");
//				getdept(data.emp_id);	
			}
		},"json");
	});
	
	
	
	
	
	//日期空间绑定事件
	$("div").delegate(".form_date","focusin",function(){
		$('.form_date').datetimepicker({
			  language: 'zh-CN',/*加载日历语言包，可自定义*/
			  pickerPosition: 'bottom-left',
			  weekStart: 1,
			  todayBtn: 1,
			  autoclose: 1,
			  todayHighlight: 1,
			  startView: 2,
			  minView: 2,
			  forceParse: 0,
			  format:"yyyy-mm-dd"
		    }).on('hide',function(e) {
		    	 $('#basicform').data('bootstrapValidator')  
		    	 .updateStatus('fabDate', 'NOT_VALIDATED',null)  
		    	 .validateField('fabDate'); 
		    });
	});
	
	
});